import { Scene } from "../../../../../Core/Module/Entity/Scene";
import { Exception } from "../../../../../Core/Object/Exception";
import { NumericComponent } from "../../../../Model/Share/Module/Numeric/NumericComponent";
import { NumericType } from "../../../../Model/Share/Module/Numeric/NumericType";
import { Unit } from "../../../../Model/Share/Module/Unit/Unit";
import { UnitComponent } from "../../../../Model/Share/Module/Unit/UnitComponent";
import { UnitType } from "../../../../Model/Share/Module/Unit/UnitType";

export class UnitFactory {

    public static Create(scene: Scene, id: number, unitType: UnitType): Unit {
        let unitComponent = scene.GetComponent<UnitComponent>(UnitComponent);
        switch (unitType) {
            case UnitType.Player:
                {
                    let unit = unitComponent.AddChildWithId<Unit, number>(Unit, id, 1001);

                    let numericComponent = unit.AddComponent<NumericComponent>(NumericComponent);
                    numericComponent.Set(NumericType.Speed, 6); // 速度是6米每秒
                    numericComponent.Set(NumericType.AOI, 15000); // 视野15米

                    unitComponent.Add(unit);
                    // 加入aoi
                    return unit;
                }
            default:
                throw new Exception(`not such unit type: ${unitType}`);
        }
    }

}